package com.xinzhi.controller;

import com.xinzhi.pojo.TransferRecord;
import com.xinzhi.service.impl.TransferRecordService;
import com.xinzhi.service.impl.TransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/api/transfer")
class TransferController {

    @Autowired
    private TransferService transferService;

    @Autowired
    private TransferRecordService transferRecordService;

    /**
     * 发起转账接口
     *
     * @param senderBankAccount   发送者银行账号
     * @param receiverName        接收者姓名
     * @param receiverBankAccount 接收者银行账号
     * @param amount              转账金额
     * @param amountInCurrency    转账对应的货币金额
     * @param exchangeRate        汇率
     * @param fee                 转账手续费
     * @param description         转账描述
     * @param currency            货币类型
     * @return 返回转账初始化成功的消息
     */
    @PostMapping("/initiate")
    public String initiateTransfer(
            @RequestParam String senderBankAccount,
            @RequestParam String receiverName,
            @RequestParam String receiverBankAccount,
            @RequestParam BigDecimal amount,
            @RequestParam BigDecimal amountInCurrency,
            @RequestParam BigDecimal exchangeRate,
            @RequestParam BigDecimal fee,
            @RequestParam String description,
            @RequestParam String currency) {
        // 根据货币类型进行金额转换

        return transferService.initiateTransfer(senderBankAccount, receiverName, receiverBankAccount,
                amount, amountInCurrency, exchangeRate, fee, description, currency);
    }

    /**
     * 获取所有转账记录接口
     *
     * @return 返回所有转账记录列表
     */
    @GetMapping("/all")
    public List<TransferRecord> getAllTransferRecords() {
        return transferRecordService.getAllTransferRecords();
    }
}